/**
 * 创建指定长度的数组
 * @param len
 */
export const createArrayByLen = (len: number) => {
  return new Array(len).fill("");
};

/**
 * 根据指定字段分组列表
 * @param list
 * @param key
 */
export const listToGroupByKey = (list: any[], key: string) => {
  const groupList: { key: string; list: any[] }[] = [];
  list.forEach(i => {
    const group = groupList.find(j => i[key] === j.key);
    group ? group.list.push(i) : groupList.push({ key: i[key], list: [i] });
  });
  return groupList;
};

/**
 * 根据指定长度分组列表
 * @param list
 * @param len
 */
export const listToGroupByLen = (list: any[], len: number) => {
  const groupList: any[][] = [];
  list.forEach(i => {
    const group = groupList[groupList.length - 1];
    group && group.length !== len ? group.push(i) : groupList.push([i]);
  });
  return groupList;
};
